package com.zhiy.com.estation.manager;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;

import com.zhiy.com.estation.app.App;
import com.zhiy.com.estation.ui.base.BaseActivity;

/**
 * All Resered by My Zong  @2016-2017
 * 存放应用中的配置信息
 * 单例模式
 */
public class PreferenceManager  {
    public static PreferenceManager mPreferenceManager;
    private  SharedPreferences mPreferences;
    private  SharedPreferences.Editor mEditor;
    private PreferenceManager(){
        if (mPreferences==null){
            mPreferences=App.getInstance().getSharedPreferences("info", Context.MODE_PRIVATE);
        }
    }
    public static PreferenceManager getInstance() {
        if (mPreferenceManager == null) {
            mPreferenceManager = new PreferenceManager();
        }
        return mPreferenceManager;
    }
    /**
     * ------------------------------------------
     *      保存登录状态的操作
     * ------------------------------------------
     * @param isAutoLogin--是否自动登录 isRemePass--是否记住密码
     */
    public void saveToAutoLogin(Boolean isAutoLogin){
        mEditor=mPreferences.edit();
        mEditor.putBoolean("isAutoLogin",isAutoLogin);
        mEditor.apply();
    }
    public boolean getAutoLogin(){
        return mPreferences.getBoolean("isAutoLogin",false);
    }
    /**
     * -------------------------------------------
     *
     * -------------------------------------------
     */
    public void saveToName(String name){
        mEditor=mPreferences.edit();
        mEditor.putString("name",name);
        mEditor.apply();
    }
    public String getName(){
        return  mPreferences.getString("name",null);
    }
    public void saveToPassword(String password){
        mEditor=mPreferences.edit();
        mEditor.putString("password",password);
        mEditor.apply();
    }
    public String getPassword(){
        return  mPreferences.getString("name",null);
    }
    public void saveToPhone(String name){
        mEditor=mPreferences.edit();
        mEditor.putString("phone",name);
        mEditor.apply();
    }
    public String getPhone(){
        return  mPreferences.getString("phone",null);
    }
    public void saveToEmail(String name){
        mEditor=mPreferences.edit();
        mEditor.putString("email",name);
        mEditor.apply();
    }
    public String getEmail(){
        return  mPreferences.getString("email",null);
    }
    //保存的是服务器图片的路径
    public void saveToavar(String name){
        mEditor=mPreferences.edit();
        mEditor.putString("avar",name);
        mEditor.apply();
    }
    public String getAvar(){
        return  mPreferences.getString("avar",null);
    }
    public void saveToUserid(int userid){
        mEditor=mPreferences.edit();
        mEditor.putInt("userid",userid);
        mEditor.apply();
    }
    public int getUserid(){
        return  mPreferences.getInt("userid",1);
    }


}
